﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.ObjectModel.Screens;
using Infrastructure.ObjectModel;
using B10_Ex02_Elad_034695114_Meyron_026607788.ObjectModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using B10_Ex02_EladLebovitch_034695114.ObjectModel;

namespace B10_Ex02_EladLebovitch_034695114.Screens
{
    public class WelcomeScreen : GameScreen
    {
        private Sprite m_WelcomeMessage;
        private Sprite m_PressEnterMsg;
        private SpriteFont m_ScoreFont;
        private Vector2 m_MessagePosition;
        private InvadorBackground m_Background;

        public WelcomeScreen(Game i_Game)
            : base(i_Game)
        {
            m_Background = new InvadorBackground(i_Game, @"Sprites\BG_Space01_1024x768");
            this.Add(m_Background);

            m_WelcomeMessage = new Sprite(@"Sprites\Welcome", this.Game);
            this.Add(m_WelcomeMessage);

            m_PressEnterMsg = new Sprite(@"Sprites\PressEnter", this.Game);
            this.Add(m_PressEnterMsg);
        }

        protected override void LoadContent()
        {
            base.LoadContent();
            m_ScoreFont = ContentManager.Load<SpriteFont>(@"Fonts\InstuctionsFont");
        }

        public override void Initialize()
        {
            base.Initialize();
            
            // Set the positions for the text
            m_WelcomeMessage.PositionOrigin = m_WelcomeMessage.SourceRectangleCenter;
            m_WelcomeMessage.PositionOfOrigin = this.CenterOfViewPort;

            m_PressEnterMsg.PositionOrigin = m_PressEnterMsg.SourceRectangleCenter;
            m_PressEnterMsg.PositionOfOrigin = new Vector2(this.m_WelcomeMessage.PositionOfOrigin.X,
                                                           this.m_WelcomeMessage.PositionOfOrigin.Y + this.m_WelcomeMessage.Height / 2 + 20);

            m_MessagePosition = new Vector2(0, this.m_WelcomeMessage.PositionOfOrigin.Y + this.m_WelcomeMessage.Height / 2 + this.m_PressEnterMsg.Height);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            SpriteBatch.Begin();
            SpriteBatch.DrawString(m_ScoreFont, 
                                    "Press Enter to start the game\n" +
                                    "Press Esc to exit\n" +
                                    "Press O for options", m_MessagePosition, Color.Red);
            SpriteBatch.End();
        }

        public override void Update(GameTime gameTime)
        {
            // Check if the user wants to go ahead
            if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Enter))
            {
                (Game.Services.GetService(typeof(GameFlow)) as GameFlow).RestartGameScreensForGame();
                this.ExitScreen();
            }
            else if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                this.Game.Exit();
            }
            else if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.O))
            {
                // Enter options
                this.ExitScreen();
            }

            base.Update(gameTime);
        }
    }
}